﻿using System;
using System.Web.UI;
using BCGC.BLL.Helper;
using BCGC.BLL.MailManager;
using BCGC.BLL.BusinessObject.UserAccount;
using Jalal.Library.Web;

public partial class Member_compose_message : MemberBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadFriends();
            AutoCompleteFriendSearch.ContextKey = SessionManager.LoggedUser.Id.ToString();
            
        }
    }

    private void LoadFriends()
    {
        
    }
    protected void tibSendMail_Click(object sender, ImageClickEventArgs e)
    {
        if (Page.IsValid)
        {
            try
            {
                SiteUser user = SiteUser.GetUserById(SessionManager.LoggedUser.Id, true);
                UserInfo receiver = UserInfo.GetUserInfoByUserName(txtFriendName.Text.Trim());


                PrivateMessage message = new PrivateMessage();
                message.Content = Server.HtmlEncode(txtBody.Text.Trim());
                message.IsActive = true;
                message.IsMarketPlaceMessage = false;
                message.IsRead = false;
                message.IsReply = false;
                message.IsSendEmail = chkSendMail.Checked;
                message.IsShowInBox = true;
                message.IsShowOutBox = true;
                message.SendDate = DateTime.Now;
                message.SenderID = SessionManager.LoggedUser.Id;
                message.SenderName = user.Username;
                message.Subject = Server.HtmlEncode(txtSubject.Text.Trim());
                message.ReceiverID = receiver.UserId;
                message.ReceiverName = receiver.Username;
                message.ReceiverEmailID = receiver.Email;
                if (message.Save())
                {
                    uccResponse.SetSuccessMessage("Message send to "+message.ReceiverName);
                }
                else
                {
                    throw new Exception("Message Not Saved");
                }
            }
            catch
            {
                uccResponse.SetFailMessage("Message Sending Failed");
            }

        }
    }
}
